﻿CREATE TABLE [investment].[Purchase] (
    [Id]                   BIGINT          IDENTITY (1, 1) NOT NULL,
    [PortfolioCode]        NVARCHAR (8)    NOT NULL,
    [MarketIdentifierCode] NVARCHAR (8)    NOT NULL,
    [StockCode]            NVARCHAR (8)    NOT NULL,
    [Quantity]             INT             DEFAULT ((0)) NOT NULL,
    [Price]                DECIMAL (28, 6) DEFAULT ((0)) NOT NULL,
    [Date]                 DATE            DEFAULT (getdate()) NOT NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [FK_Purchase_Portfolio] FOREIGN KEY ([PortfolioCode]) REFERENCES [investment].[Portfolio] ([Code]),
    CONSTRAINT [FK_Purchase_Stock] FOREIGN KEY ([MarketIdentifierCode], [StockCode]) REFERENCES [investment].[Stock] ([MarketIdentifierCode], [Code])
);









